/**
 * 
 */
package ua.kpi.javatrainee6.model.departments;

import ua.kpi.javatrainee6.model.curriculum.*;
import ua.kpi.javatrainee6.model.people.*;

import java.util.Date;

/**
 * University entity, contains UniversityAdministrator entity
 * Provides next functionality: you can view all members, students,
 * professors, subjects and groups of university. Also you can view 
 * curriculum of all university 
 */
public final class University extends Department implements CurriculumPrintable {
	
	private UniversityAdministrator admin;
	
	/**
	 * @param title - University tile
	 * @param creationDate - University creation date
	 */
	public University(String title, Date creationDate) {
		super(title, creationDate);
		performAdministrativeTasks();
	}
	
	/**
	 * Creating new instance of University Administrator, during it
	 * students and professors are enrolled, groups are formed,
	 * curricular is created
	 */
	private void performAdministrativeTasks() {
		admin = new UniversityAdministrator(this);
	}
	
	/**
	 * For testing purposes you need instance of Administrator class
	 * @return university administrator
	 */
	public UniversityAdministrator getAdmin() {
		return admin;
	}
	
	/**
	 * Is called by Professor, Student, Group entities to get their own curricular
	 * @return Curriculum entity
	 */
	public Curriculum getCurriculum() {
		return admin.getCurriculum();
	}
	
	/**
	 * CurriculumPrintable interface method, for University you can
	 * view curricular for all groups
	 */
	public void viewCurriculum() {
		Curriculum curriculum = admin.getCurriculum();
		System.out.println("Curriculum for all university " + this.getTitle());
		curriculum.printCurriculum();
	}
	
	/**
	 * Viewing list of groups, implementation of abstract method from
	 * Department base class
	 */
	public void viewAllSections() {
		System.out.println("All groups in the university:");
		admin.getGroups().print();
	}
	
	/**
	 * Viewing list of students
	 */
	public void viewAllStudents() {
		System.out.println("All students in the university:");
		for (Group group : admin.getGroups()) {
			System.out.println("For group " + group.getTitle());
			group.viewAllMembers();	
		}
	}
	
	/**
	 * Viewing list of teachers
	 */
	public void viewAllProfessors() {
		System.out.println("All professors in the university:");
		for (Professor professor : admin.getProfessors()) {
			System.out.println(professor);
		}
	}
	
	/**
	 * Implementation of abstract method from Department class
	 * For university - you can view students and professors 
	 */
	public void viewAllMembers() {
		viewAllStudents();
		viewAllProfessors();	
	}
	
	/**
	 * Implementation of abstract method from Department class
	 * For university - you can view all subjects for all groups
	 */
	public void viewAllSubjects() {
		System.out.println("All subjects in the university " + super.getTitle());
		for (Subject subject : admin.getSubjects()) {
			System.out.println(subject);
		}
	}
	
	@Override
	public String toString() {
		return super.toString();
	}
	
	@Override
	public boolean equals(Object otherObject) {
		if (! super.equals(otherObject)) {
			return false;
		}
		University other = (University) otherObject;
		if (admin.equals(other.admin)) {
			return true;
		} else {
			return false;
		}
	}	
}
